package com.yunxi.service.localService.sys.impl;

import com.github.pagehelper.PageInfo;
import com.yunxi.core.web.TreeConfig;
import com.yunxi.dao.sys.OrgMapper;
import com.yunxi.model.sys.Org;
import com.yunxi.service.localService.sys.OrgService;
import com.yunxi.sys.pojo.OrgListVO;
import com.yunxi.sys.pojo.OrgVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.yunxi.core.service.ServiceImplPlus;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 组织结构 服务实现类
 * </p>
 *
 * @author caoYong
 * @since 2019-05-08
 */
@Service
@Qualifier("orgServiceImpl")
public class OrgServiceImpl extends ServiceImplPlus<OrgMapper, Org> implements OrgService {

    @Autowired
    OrgMapper orgMapper;

    @Override
    public Object findTreeListBySysType(String org_type) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
       // org_type 0厂端 1店端
       Map map = new HashMap();
        map.put("org_type",org_type);

        List list = orgMapper.findAll(map);
        if(org_type!=null&&org_type.equalsIgnoreCase("0")){
            TreeConfig config = new TreeConfig("0", "组织", true, "orgId", "orgName", "pid", "hasChild");
            return config.toTreeData(list,false);
        }else{
            TreeConfig config = new TreeConfig("0", "组织", true, "orgId", "orgName", "pid", "hasChild");
            return config.toTreeData(list,false);
        }
    }

    @Override
    public Object treeByPid(String pid) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        // org_type 0厂端 1店端
        Map map = new HashMap();
        map.put("pid",pid);

        List list = orgMapper.findAll(map);
        TreeConfig config = new TreeConfig(pid, "组织", true, "orgId", "orgName", "pid", "hasChild");
        Object o  = config.toTreeData(list,false);
        return o;
    }

    @Override
    public PageInfo findPageByVO(OrgVO orgVO, Integer pageNum, Integer pageSize){
        PageInfo pageInfo = pageByVo(orgVO, pageNum, pageSize);
        return pageInfo;
    }

    @Override
    public List<OrgListVO> getOrgList() {
        List<OrgListVO> orgList = baseMapper.getOrgList();
        return orgList;
    }
}
